package zzxkj.blog.cacheService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import zzxkj.blog.common.lang.Consts;
import zzxkj.blog.service.CommentService;
import zzxkj.blog.utils.RedisUtil;

import java.util.List;

/**
 * admin echarts data
 * @author zzxkj
 */
@Slf4j
@Component
public class EchartsDataService {
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private CommentService commentService;
    //CHART_VIEW_DATA

    /**
     * 获取周浏览量的数据
     * @return
     */
    public List<Object> getChartViewData(){
        if(!redisUtil.hasKey(Consts.CHART_VIEW_DATA_KEY)){
            log.error("Not Exist Key ----> {}", Consts.CHART_VIEW_DATA_KEY);
            return null;
        }
        List<Object> data = redisUtil.lGet(Consts.CHART_VIEW_DATA_KEY, -7, -1);
        return data;
    }
    /**
     * 获取周评论量的数据
     * @return
     */
    public List<Object> getChartCommentsData(){
        return commentService.getDayCommentsCountOf7Days();
    }
}
